package com.example.controller;

import com.example.common.R;
import com.example.entity.Banteacher;
import com.example.entity.Page;
import com.example.service.AdminService;
import com.example.service.BanteacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("banteachers")
public class BanteacherController {

    private R r;

    @Autowired
    private BanteacherService banteacherService;

    /**
     * 分页查询所有管理员信息
     * @return
     */

    @GetMapping("/getPageBanteacher/{currentPage}/{pageSize}")

    public R getPage(@PathVariable int currentPage,@PathVariable int pageSize){

        List<Banteacher> page = banteacherService.getPage(currentPage,pageSize);
        int count = banteacherService.getTotalCount();

        return R.success("分页查询所有banteachers成功！",new Page<Banteacher>(count,page));
    }

    /**
     * 添加
     * @param banteacher
     * @return
     */
    @PostMapping("/addBanteacher")
    public R add(@RequestBody Banteacher banteacher){

        Boolean update = banteacherService.add(banteacher);
        if (update){
            return R.success("添加banteacher成功!",null);
        }
        return R.error("添加banteacher失败!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteBanteacher/{id}")
    public R deleteById(@PathVariable int id){

        Boolean byId = banteacherService.deleteById(id);
        if (byId){
            return R.success("删除banteachers成功!",null);
        }
        return R.error("删除banteachers失败!");
    }

    /**
     * 修改
     * @param banteacher
     * @return
     */
    @PutMapping("/updateBanteacher")
    public R deleteById(@RequestBody Banteacher banteacher){

        Boolean update = banteacherService.update(banteacher);
        if (update){
            return R.success("修改banteacher成功!",null);
        }
        return R.error("修改banteacher失败!");
    }


}

